package com.david.learning.annotation;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class AnnotationTest {
	private JFrame mainWin = new JFrame(
			"Use Annotation to bundle event listensers");

	@ActionListenerFor(listener = OkListener.class)
	private JButton ok = new JButton("Submit");

	@ActionListenerFor(listener = CancelListener.class)
	private JButton cancel = new JButton("Cancel");

	public void init() {
		JPanel jp = new JPanel();
		jp.add(ok);
		jp.add(cancel);
		mainWin.add(jp);
		ActionListenerInstaller.processAnnotations(this);
		mainWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		mainWin.setVisible(true);
		mainWin.pack();
	}

	public static void main(String[] args) {
		new AnnotationTest().init();
	}
}

class OkListener implements ActionListener {
	public void actionPerformed(ActionEvent evt) {
		JOptionPane.showMessageDialog(null, "clicked the submit button");
	}
}

class CancelListener implements ActionListener {
	public void actionPerformed(ActionEvent evt) {
		JOptionPane.showMessageDialog(null, "clicked the cancel button");
	}
}
